package com.gp.study.mybatis;

import java.sql.SQLException;

public class GpSqlSession {
	//需要一个获取代理对象的方法
	GpConfigurattion configuration;
	//执行器
	GPExecutor executor;
	
	public GpSqlSession(GpConfigurattion configuration,GPExecutor executor) {
		this.configuration = configuration;
		this.executor =executor;
	}
	
	
	public <T> T selectOne(String statementId,Object parm) throws ClassNotFoundException, SQLException{
		String sql = configuration.sqlMappings.getString(statementId);
		if(null!= sql && !"".equals(sql)){
			return executor.query(sql,parm);
		}
		return null;
	}
	/**
	 * 根据接口类型获取代理对象
	 * @param clz
	 * @return
	 */
	public <T> T getMapper(Class<?> clz){
		return (T)configuration.getMapper(clz,this);
	}

}
